package com.caogen.cg_wl_kt.vmodel.login

import com.caogen.cg_wl_kt.api.LoginApi
import com.caogen.cg_wl_kt.base.BaseP
import com.caogen.cg_wl_kt.base.BaseViewModel
import com.caogen.cg_wl_kt.model.UserBean
import com.caogen.cg_wl_kt.ui.login.LoginActivity
import com.caogen.cg_wl_kt.utils.PrefUtils
import com.caogen.cg_wl_kt.utils.YDLog

/**
 * 项目名称: cg_wl_kt
 * Packages:com.caogen.cg_wl_kt.ui.login.vmodel
 * author: FSW
 * 创建日期: 2024/2/27 18:02
 * Describe:
 *
 */
class LoginViewModel:BaseViewModel() {

    fun login(activity:LoginActivity){
        val params = HashMap<String,String>()
        params["account"] = activity.binding.evUser.text.toString().trim()
        params["password"] = activity.binding.evPwd.text.toString().trim()
        LoginApi.reqLogin(activity, params,object : BaseP.OnBeanCallBack{
            override fun <T> onSuccess(data:T?) {
                val user = data as UserBean;
                YDLog.logi(user.token.toString())
                PrefUtils.put(activity, PrefUtils.LOGIN_TOKEN,user.token.toString())
                var token = PrefUtils.get(activity, PrefUtils.LOGIN_TOKEN,"");

                YDLog.logi(token.toString())
            }

            override fun <T> onError(data: T?) {
                YDLog.logi(data.toString())
            }
        })
    }
}